package com.woniuxy.joylife.manager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.joylife.manager.dao.RoomDao;
import com.woniuxy.joylife.manager.entity.RoomEntity;
import com.woniuxy.joylife.manager.service.RoomService;
import com.woniuxy.joylife.manager.utils.PageUtils;
import com.woniuxy.joylife.manager.utils.Query;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("roomService")
public class RoomServiceImpl extends ServiceImpl<RoomDao, RoomEntity> implements RoomService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<RoomEntity> page = this.page(
                new Query<RoomEntity>().getPage(params),
                new QueryWrapper<RoomEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public Boolean saveRoomEntity(RoomEntity room) throws Exception {
        // 查询是否重名
        QueryWrapper<RoomEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",room.getName());
        RoomEntity roomEntity = baseMapper.selectOne(queryWrapper);
        if (roomEntity==null){
            baseMapper.insert(room);
            return true;
        }else{
            return false;
        }
    }

}